// pages/voucher/voucher.js
const $api = require('../../utils/request').Api;
const login = wx.getStorageSync('login') // login.data.data.memberNumber
const app = getApp()
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
    baseImgUrl: app.globalData.baseImgUrl,
		activeNames: ['1'],
		isFold: false,
		leimingqu: '',
		listdata: []
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		this.getListUserVoucher()
	},
	handleTrigger(e) {
		this.isFold = !this.isFold;
		// if(e.currentTarget.dataset.item){}
		if (this.isFold === true) {
			this.leimingqu = e.currentTarget.dataset.item ? e.currentTarget.dataset.item : '0'
		} else {
			if (this.leimingqu != '') {
				console.log(e.currentTarget.dataset.item.index == this.leimingqu.index);
				this.leimingqu = e.currentTarget.dataset.item.index == this.leimingqu.index ? '0' : e.currentTarget.dataset.item
			} else {

			}
			// this.leimingqu = e.currentTarget.dataset.item ? '0' : '0'
		}
		console.log(this.leimingqu);
		this.setData({
			isFold: this.isFold,
			leimingqu: this.leimingqu
		})
	},
	onChange(event) {
		this.setData({
			activeNames: event.detail,
		});
	},
	getListUserVoucher () {
		$api.getListUserVoucher({ memberNumber: login.data.data.memberNumber, pageNum: 1, pageSize: 10 }).then(({ data: res }) => {
			this.setData({ listdata: res.data.list.map((item, index) => ({ ...item, index: index + 1 + '' })) })
		})
	}
})
